<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<#include '/common/head.html'>
	<#include '/common/fileupload.html'>
	<script type="text/javascript">
		var $obj = {}, $category_dg, $article_dg , $window ;
		$(function() {
			$obj = {
				init: function() {
					$category_dg = $('#category_dg').datagrid({
						title: '微信图文类别', url: '/weixin/news/category/list', 
						method: 'GET', nowrap: true, striped: true, singleSelect: false,
						checkbox: true, pagination: true, pageSize: 30, pageList: [30,40,50,100,200,500,1000],
						autoRowHeight: true, fit: true, border: false, rownumbers: true, rownumberWidth: 40, toolbar: "#category_toolbars", 
						remoteSort: true, sortName: 'id', sortOrder: 'desc', queryParams: {},
						frozenColumns: [[
							{title: 'ID', field: 'id', hidden: true},
							{title: '类别名称', field: 'category', width: 230}
						]],
						columns: [[
							{title: '状态', field: 'status', width: 70, align: 'center', formatter: function(value, row, index) {
								if(value==0) return '禁用';
								else if(value==1) return '正常';
								else return '-';
							}},
							{title: '排序', field: 'orderNum', width: 50}
						]]
					});
					
					$article_dg = $('#article_dg').datagrid({
						title: '微信图文列表', url: '/weixin/news/article/list', 
						method: 'GET', nowrap: true, striped: true, singleSelect: false,
						checkbox: true, pagination: true, pageSize: 30, pageList: [30,40,50,100,200,500,1000],
						autoRowHeight: true, fit: true, border: false, rownumbers: true, rownumberWidth: 40, toolbar: "#article_toolbars", 
						remoteSort: true, sortName: 'id', sortOrder: 'desc', queryParams: {},
						frozenColumns: [[
							{title: 'ID', field: 'id', hidden: true},
							{title: '标题', field: 'title', width: 200}
						]],
						columns: [[
							{title: '状态', field: 'status', width: 70, align: 'center', formatter: function(value, row, index) {
								if(value==0) return '禁用';
								else if(value==1) return '正常';
								else return '-';
							}},
							{title: '跳转URL', field: 'url', width: 300, align: 'center', formatter: function(value, row, index) {
								if(null != value && "" != value) {
									return '<a href="'+value+'" target="blank" style="color:blue">'+value+'<a/>';
								} else {
									return '-';
								}
							}},
							{title: '图片', field: 'picUrl', width: 220, align: 'center', formatter: function(value, row, index) {
								if(null != value && "" != value) {
									return '<a href="'+value+'" target="blank"><img src="'+value+'" width="200" height="80" style="margin:5px;" alt="图片不存在！"><a/>';
								} else {
									return '-';
								}
							}},
							{title: '图文描述', field: 'description', width: 300},
							{title: '排序', field: 'orderNum', width: 50},
							{title: '创建时间', field: 'createTime', width: 130, align: 'center', formatter: function(value, row, index) {
								return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
							}},
							{title: '创建者', field: 'createBy', width: 70},
							{title: '更新时间', field: 'updateTime', width: 130, align: 'center', formatter: function(value, row, index) {
								return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
							}},
							{title: '更新者', field: 'updateBy', width: 70}
						]]
					});
				},
				category_add: function() {
					$window = MM.addWindow({title: '添加类别', href: '/weixin/news/form_category', width: 330, height: 200});
				},
				article_add: function() {
					var row = $category_dg.datagrid('getSelections') ;
					if(null != row && row.length == 1) {
						$window = MM.addWindow({title: '添加', href: '/weixin/news/form_article?categoryId='+row[0].id, width: 600, height: 391});
					} else {
						alertify.warning("请选择一条类别记录");
					}
				},
				category_del: function() {
					var ids = MM.getSelectionsIds('#category_dg') ;
					if(ids) {
						$.messager.confirm('删除确认', '确定要删除？', function(r) {
							if(r) {
								$.get('/weixin/news/delete/category/'+ids, function(result) {
									try {
										if(result.code == 200) {
											$obj.category_reload(); alertify.success(result.message);
										} else {
											alertify.warning(result.message);
										}
									} catch(e) {
										$.easyui.loaded(); console.error(e) ;
									}
								}, 'JSON').complete(function(){$.easyui.loaded();});
							}
						});
					} else {
						alertify.error('至少选择一条记录');
					}
				},
				article_del: function() {
					var ids = MM.getSelectionsIds('#article_dg') ;
					if(ids) {
						$.messager.confirm('删除确认', '确定要删除？', function(r) {
							if(r) {
								$.get('/weixin/news/delete/article/'+ids, function(result) {
									try {
										if(result.code == 200) {
											$obj.article_reload(); alertify.success(result.message);
										} else {
											alertify.warning(result.message);
										}
									} catch(e) {
										$.easyui.loaded(); console.error(e) ;
									}
								}, 'JSON').complete(function(){$.easyui.loaded();});
							}
						});
					} else {
						alertify.error('至少选择一条记录');
					}
				},
				category_update: function() {
					var row = $category_dg.datagrid('getSelected') ;
					if(null != row && row.id != "") {
						$window = MM.addWindow({title: '修改', href: '/weixin/news/form_category?id='+row.id, width: 330, height: 200});
					} else {
						alertify.error('请选择一条记录');
					}
				},
				article_update: function() {
					var row = $article_dg.datagrid('getSelected') ;
					if(null != row && row.id != "") {
						$window = MM.addWindow({title: '修改', href: '/weixin/news/form_article?id='+row.id, width: 600, height: 391});
					} else {
						alertify.error('请选择一条记录');
					}
				},
				category_reload: function() {
					$category_dg.datagrid('reload'); $category_dg.datagrid('clearSelections');$category_dg.datagrid('clearChecked');
				},
				article_reload: function() {
					$article_dg.datagrid('reload'); $article_dg.datagrid('clearSelections');$article_dg.datagrid('clearChecked');
				},
				category_row: function() {
					return $category_dg.datagrid("getSelected");
				}
			};
			
			$obj.init() ;
		});
	</script>
</head>

<body>
	
	<div id="mainLayout" class="easyui-layout" data-options="fit: true">
		<!-- 左 -->
		<div data-options="region: 'west', split: true, minWidth: 420, maxWidth: 500" style="width: 420px;">
			<div id="category_dg">
				<div id="category_toolbars"> 
					<a onclick="$obj.category_add();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-add'">添加</a> 
					<a onclick="$obj.category_update();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-edit'">编辑</a> 
					<a onclick="$obj.category_del();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-cancel'">删除</a> 
					<a onclick="$obj.category_reload();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-reload'">刷新</a> 
				</div>
			</div>
		</div>
		
		<!-- 中 -->
		<div data-options="region: 'center', border:true">
			<div id="article_dg">
				<div id="article_toolbars"> 
					<a onclick="$obj.article_add();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-add'">添加</a> 
					<a onclick="$obj.article_update();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-edit'">编辑</a> 
					<a onclick="$obj.article_del();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-cancel'">删除</a> 
				</div>
			</div>
		</div>
		
	</div>
</body>
</html>
